package main

// 调用Linux的stat()

/*
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
*/
import "C"

import (
	"fmt"
	"os"
	"unsafe"
)

func main() {
	var s C.struct_stat
	var ret C.int
	path := C.CString(os.Args[1])
	defer C.free(unsafe.Pointer(path)) //free(void*) 所以入参要转换为unsafe.Pointer
	// 调用 linux 的 stat()
	ret, e := C.stat(path, &s) //e 是string化的 errno

	fmt.Printf("stat() return code %d, error str: %v\n", ret, e)
	fmt.Printf("size of file %q :%d bytes\n", os.Args[1], s.st_size)
}
